<?php
		require("../dbconnect.php");
		require("../email.php");
		
		$id=$_GET["q"];
		$paytype=$_GET["paytype"];
		
		if($paytype==1) //ebanking or cod
		{
			$get_bill=mysql_query("select * from os_bill_details where id=$id");
			$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
			
			$email=$b['email'];
			email_orderrequest($b['id']);
			$invoice_number=$b['invoice_number'];
			$update=mysql_query("update os_bill_details set status=1 where id=$id");
			
			$content="<img src='images/icons/tick.jpg' align='absmiddle'> An order request has been sent to $email,  if you haven't received it within 5 minutes, kindly check your junk mail or contact us for assistant. 
				<br> Please record your invoice number : <b>$invoice_number</b> for future reference.";
		
		}
		else // paypal
		{
			$get_bill=mysql_query("select * from os_bill_details where id=$id");
			$b=mysql_fetch_array($get_bill,MYSQL_ASSOC);
			$get_item=mysql_query("select * from os_bill_items where bid=$id")or die("line 11".mysql_error());
			$count=mysql_num_rows($get_bill);
			$get_info=mysql_query("select * from os_contactinfo where id=1");
			$i=mysql_fetch_array($get_info,MYSQL_ASSOC);
			$websitename_eng=$i['website_name'];
			$paypal_submit_url=$i['paypal_submit_url'];
			$logo_url=$i['logo_url'];
			$os_url=$i['website'];
			$get_currency=mysql_query("select currency_code from os_currency where is_main=1")or die(mysql_error());
			$currency_code=mysql_result($get_currency,0,"currency_code");
			$paypal_emailaddress=$i['paypal_emailaddress'];
			$shipping=number_format($b['transport_fees'],2);
			$invoice_number=$b['invoice_number'];
			
			$update=mysql_query("update os_bill_details set status=-3 where id=$id");
			
			$content=
			"<form method='post' action='$paypal_submit_url'>
			<input type='hidden' name='cmd' value='_cart'>
			<input type='hidden' name='upload' value='1'>
			<input type='hidden' name='business' value='$paypal_emailaddress'>
			<input type='hidden' name='currency_code' value='$currency_code'>
			<input type='hidden' name='image_url' value='$logo_url'>
			<input type='hidden' name='cancel_return' value='$os_url'>
			<input type='hidden' name='return' value='$os_url'>
			<input type='hidden' name='shipping' value='$shipping'>
			<input type='hidden' name='invoice' value='$invoice_number'>
			<input type='hidden' name='no_shipping' value='1'>
			<input type='hidden' name='rm' value='2'>
			
			";
			
			$no=1;
			while($c=mysql_fetch_array($get_item))
			{
			
				$get_product=mysql_query('select * from os_products where id='.$c['pid']);
				$a=mysql_fetch_array($get_product,MYSQL_ASSOC);
				
				$content.="
					<input type='hidden' name='item_name_$no' value='".$a['product_name_eng']."'>
					<input type='hidden' name='amount_$no' value='".$c['price']."'>
					<input type='hidden' name='quantity_$no' value='".$c['quantity']."'>";
				$no++;
			}
			$no=$no-1;
			$content.="
			<input type='hidden' name='shipping_$no' value='$shipping'>
			
			
			Click the button below to redirect to <img src='images/p1.gif' align='absmiddle'> payment page<br>
			<input type='submit' name='sub' class='button' value='Proceed to Paypal now'> 
			</form>";
		}
		echo iconv('GBK', 'utf-8', $content);
		
?>